n = int(input())
edges = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w = map(int,input().split())
    edges[u].append((v,w))
    edges[v].append((u,w))
max_length = 0
def dfs(root:int,parent):
    global max_length
    # 返回子树的最大距离
    dis = [dfs(target,root) + w for target,w in edges[root] if target != parent]
    dis.sort()
    if len(dis) >= 2: max_length = max(max_length, dis[-1] + dis[-2])
    elif len(dis) >= 1: max_length = max(max_length, dis[0])
    return dis[-1] if dis else 0

dfs(1,-1)
print((21+max_length)*max_length//2)